-- damage_element
-- create by panyl
-- 元素射线: 单体，对目标施加伤害
-- 伤害的计算规则：攻击者的攻击 * 威力 * 加成
-- 目前支持如下两种配置：
-- 1、damage(1200)：对目标造成120%的魔法伤害

return {
    apply = function(source, target, skillId, round, para, extra)
        -- 威力
        local force = para[1];

        -- 2. 攻击方的魔力
        local attack = source:getAttack();

        -- 被对方百分比削弱
        local prop = PropM.combine(target, "weak_enemy", "attack");
        attack = PropM.apply(prop, attack);

        -- 被对方绝对值削弱
        prop = PropM.combine(target, "weak_enemy2", "attack");
        attack = PropM.apply(prop, attack);

        -- 3. 伤害/计算伤害时魔力+3
        local damage = math.modf(force * attack / 1000);

        if #para > 1 and tonumber(para[2]) == target.style then
            -- 该系别有伤害加成
            damage = math.modf(para[3] * damage / 1000);
        end

        -- 增加命中动作
        SkillM.getSequence(target):hit(source, target, skillId);

        -- 伤害
        CombatM.receiveDamage(source, target, damage, skillId, extra);

        -- 作用目标
        return { target, };
    end,

    parse = function(desc)
        local arr = string.explode(desc, ",");
        if (#arr == 1) then
            return { tonumber(arr[1]), };
        else
            return { tonumber(arr[1]), arr[2], tonumber(arr[3]) };
        end
    end,

    -- 解析技能描述
    parseDesc = function(source, skillId, desc, para)
        -- 威力
        local force = para[1];

        -- 2. 攻击方的魔力
        local attack = source:getAttack();

        -- 3. 伤害
        local damage = math.modf(force * attack / 1000);

        desc = string.gsub(desc, "{damage_element}", damage);

        -- 系别TODO

        return desc;
    end,
};
